import { defineStore } from 'pinia'
import { Names } from './storeNamespace'

export interface IMenuTabs {
    title: string,
    path: string
}

interface ITabsStore {
    menuTabsList: Array<IMenuTabs>
}

const tabsStore = (): ITabsStore => {
    return {
        menuTabsList: [{ "path": "/home", "title": "后台首页" }]
    }
}

export const useTabsStore = defineStore(Names.Tabs, {
    state: () => tabsStore(),
    persist: {
        enabled: true,
        strategies: [
            {
                storage: sessionStorage,
                paths: ['menuTabsList',]
            }
        ]
    },
    getters: {
        getMenuTabsList: (store) => store.menuTabsList
    },
    actions: {
        addMenuTabs(tab: IMenuTabs) {
            // 如果选项卡有当前菜单
            if (this.menuTabsList.some(item => item.path === tab.path)) return
            // 添加选项卡
            this.menuTabsList.push(tab)
        }
    }
})